/**
  ******************************************************************************
  * @file    Libraries/Device/TS32F020X/TS32F020X_LL_Driver/inc/ts32f020x_ll_lvd.h
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    02-19-2022
  * @brief   This file contains all the LVD LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 
  
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TS32F020X_LL_LVD_H
#define __TS32F020X_LL_LVD_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "ts32f020x.h"
     
/** @addtogroup TS32F020X_StdPeriph_Driver TS32F020X Driver
  * @{
  */
     
/** @addtogroup lvd_interface_gr LVD Driver
  * @ingroup  TS32F020X_StdPeriph_Driver
  * @{
  */ 

/** @addtogroup LVD_LL_Driver LVD LL Driver
  * @ingroup  lvd_interface_gr
  * @brief Mainly the driver part of the LVD module, which includes \b LVD \b Register 
  * \b Constants, \b LVD \b Exported \b Constants, \b LVD \b Exported \b Struct, \b LVD
  * \b Data \b transfers \b functions, \b LVD \b Initialization \b and \b LVD \b Configuration 
  * \b And \b Interrupt \b Handle \b function.
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/** @defgroup LVD_LL_Register_Constants LVD LL Register Constants
  * @ingroup  LVD_LL_Driver
  * @brief    LVD LL register constant table definition
  *
  *
@verbatim   
  ===============================================================================
                                Register Constants
  ===============================================================================  
  
    Register Constants mainly encapsulates each bit in each group in the LVD 
    register. In the process of configuration, the macro definition can be directly 
    called to configure the LVD register, mainly for convenience. Understand the 
    configuration of the LVD.
    
@endverbatim
  *
  * @{
  */

/***** LVDCON(LVD Config Register reset: 0xc000 0e23) *****/
/*! VDD voltage below the set threshold triggers pending, write 0 clean this bit
 */
#define LL_LVD_CON_VDD_PEND                                 (1UL << 31)

/*! VCC voltage below the set threshold triggers pending, write 0 clean this bit
 */
#define LL_LVD_CON_VCC_PEND                                 (1UL << 30)

/*! VDD LD0 enable analog signal output
 * 0: enable  
 * 1: disable 
 */
#define LL_LVD_CON_VDD_ANA_LVD_DIS                          (1UL << 29)

/*! Filter detection voltage signal low burr width, unit is the system clock period
 */
#define LL_LVD_CON_VDD_DBS_LO_LIMIT(n)                      ((n & 0x7F) << 22)

/*! Filter detection voltage signal high burr width, unit is the system clock period
 */
#define LL_LVD_CON_VDD_DBS_HI_LIMIT(n)                      ((n & 0x7F) << 15)

/*! Detected whether synchronization is required for interrupt mode triggered by VCC low-voltage signal  
 * 0: synchronous  
 * 1: asynchronism  
 */
#define LL_LVD_CON_VCC_SYNC_DIS                             (1UL << 14)

/*! VDD voltage status signal after enable shield debounce to be sampled  
 * 0: dis shield   
 * 1: en shield  
 */
#define LL_LVD_CON_VDD_SHIELD_DEBOUNCE_EN                   (1UL << 13)

/*! VCC voltage status signal after enable shield debounce to be sampled  
 * 0: dis shield  
 * 1: en shield  
 */
#define LL_LVD_CON_VCC_SHIELD_DEBOUNCE_EN                   (1UL << 12)

/*! LVD digital switch to enable LVD events to be reset or interrupted
 * 0: disable  
 * 1: enable  
 */
#define LL_LVD_CON_LVD_DIG_EN                               (1UL << 11)

/*! VDD threshold determines whether the reset system is enabled after triggering  
 * 0: interrupt, not reset  
 * 1: reset, not interrupt  
 */
#define LL_LVD_CON_VDD_RST_EN                               (1UL << 10)

/*! VCC threshold determines whether the reset system is enabled after triggering  
 * 0: interrupt, not reset  
 * 1: reset, not interrupt  
 */
#define LL_LVD_CON_VCC_RST_EN                               (1UL << 9)

/*! VCC LD0 enable analog signal output  
 * 0: enable  
 * 1: disable  
 */
#define LL_LVD_CON_VCC_LVD_ANA_OUTPUT_DIS                    (1UL << 8)

/*! VDD LVD voltage detection setting (unit V)  
0000=1.15
0001=1.20
0010=1.25
0011=1.30
0100=1.35
0101=1.40
0110=1.45
0111=1.50
 */
#define LL_LVD_CON_VDD_LVD_SET(n)                           ((n & 0x07) << 5)

/*! VDD LVD analog switch enables VDD LVD voltage to be detected  
 * 0: disable  
 * 1: enable  
 */
#define LL_LVD_CON_VDD_LVD_EN                               (1UL << 4)

/*! VCC LVD set  
000=2.10
001=2.20
010=2.40
011=2.50
100=2.70
101=3.00
110=3.60
111=4.20
 */
#define LL_LVD_CON_VCC_LVD_SET(n)                           ((n & 0x07) << 1)


/*! VCC LVD analog switch enables VDD LVD voltage to be detected  
 * 0: disable  
 * 1: enable  
 */
#define LL_LVD_CON_VCC_LVD_EN                               (1UL << 0)


/***** LVDCON1(LVD Config Register reset: 0x0) *****/
/*! Filter detection voltage signal low burr width, unit is the system clock period
 */
#define LL_LVD_CON1_VCC_DBS_LO_LIMIT(n)                      ((n & 0x7F) << 8)

/*! Filter detection voltage signal high burr width, unit is the system clock period
 */
#define LL_LVD_CON1_VCC_DBS_HI_LIMIT(n)                      ((n & 0x7F) << 0)



/**
  * @}
  */

/** @defgroup LVD_LL_Exported_Constants LVD LL Exported Constants
  * @ingroup  LVD_LL_Driver
  * @brief    LVD LL external constant definition
  *
@verbatim   
  ===============================================================================
                                Exported Constants
  ===============================================================================  
  
    Exported Constants mainly restricts the partial configuration of the abstraction 
    layer by using the form of enumeration to facilitate the use and understanding of 
    the module configuration. For the specific enumeration meaning, please refer to 
    the annotation of each module.

@endverbatim
  *
  * @{
  */

/***** DRIVER API *****/


/***** LL API *****/

/**
  * @brief Enumeration constant for vdd lvd set voltage
  */
typedef enum {
    /*! vdd lvd set 1.15
     */
    LL_LVD_VDD_LVD_SET_1_15     = 0x00,
    /*! vdd lvd set 1.20
     */
    LL_LVD_VDD_LVD_SET_1_20     = 0x01,
    /*! vdd lvd set 1.25
     */
    LL_LVD_VDD_LVD_SET_1_25     = 0x02, 
    /*! vdd lvd set 1.30
     */
    LL_LVD_VDD_LVD_SET_1_30     = 0x03,
    /*! vdd lvd set 1.35
     */
    LL_LVD_VDD_LVD_SET_1_35     = 0x04,
    /*! vdd lvd set 1.40
     */
    LL_LVD_VDD_LVD_SET_1_40     = 0x05, 
    /*! vdd lvd set 1.45
     */
    LL_LVD_VDD_LVD_SET_1_45     = 0x06,
    /*! vdd lvd set 1.50
     */
    LL_LVD_VDD_LVD_SET_1_50     = 0x07, 

} TYPE_ENUM_LL_LVD_VDD_LVD_SET;

/**
  * @brief Enumeration constant for vcc lvd set voltage
  */
typedef enum {
    /*! vcc lvd set 1.8
     */    
    LL_LVD_VCC_LVD_SET_1_8      = 0x00,
    /*! vcc lvd set 2.0
     */    
    LL_LVD_VCC_LVD_SET_2_0      = 0x01,
    /*! vcc lvd set 2.2
     */
    LL_LVD_VCC_LVD_SET_2_2      = 0x02,
    /*! vcc lvd set 2.4
     */
    LL_LVD_VCC_LVD_SET_2_4      = 0x03,
    /*! vcc lvd set 2.7
     */
    LL_LVD_VCC_LVD_SET_2_7      = 0x04,
    /*! vcc lvd set 3.0
     */
    LL_LVD_VCC_LVD_SET_3_0      = 0x05,
    /*! vcc lvd set 3.6
     */
    LL_LVD_VCC_LVD_SET_3_6      = 0x06,
    /*! vcc lvd set 4.2
     */
    LL_LVD_VCC_LVD_SET_4_2      = 0x07,    
} TYPE_ENUM_LL_LVD_VCC_LVD_SET;

 /**
  * @brief Enumeration constant for vdd lvd set voltage
  */
typedef enum {
    /*!
        synchronous  
     */
    synchronous                 = 0,
    /*!
        asynchronism  
     */
    asynchronism                = 1,

} TYPE_ENUM_LL_LVD_VCC_SYNC_EN; 


/***** LL API AND DRIVER API *****/


/**
  * @}
  */

/** @defgroup LVD_LL_Exported_Struct LVD LL Exported Struct
  * @ingroup  LVD_LL_Driver
  * @brief    LVD LL external configuration structure definition
  *
@verbatim   
  ===============================================================================
                                Exported Struct
  ===============================================================================  

    Exported Struct mainly extracts the LVD registers from the API, and abstracts 
    the structure. As long as it implements the low coupling between the registers 
    and the registers, the user only needs to configure the structure of the abstraction 
    layer and call hal_lvd_init. Function, you can configure the LVD module without 
    involving the configuration of the collective register.

@endverbatim
  *
  * @{
  */



/**
  * @}
  */

/** @defgroup LVD_LL_Interrupt LVD LL Interrupt Handle function
  * @brief   LVD LL Interrupt Handle function
  *
@verbatim   
  ===============================================================================
                        Interrupt Handle function
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the LVD  
    Interrupt Handle function.

    how to use?

    The LVD interrupt handler uses a callback method that reserves the interface 
    to the user in the form of a callback function. The client needs to initialize 
    the callback function when initializing the LVD in order for the interrupt to 
    be processed normally. 
   
@endverbatim
  *
  * @{
  */

/**
  * @}
  */
  
/** @defgroup LVD_LL_Inti_Cfg LVD LL Initialization And Configuration
  * @brief    LVD LL Initialization And Configuration
  *
@verbatim   
  ===============================================================================
                        Initialization And Configuration
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the LVD data 
    Initialization and Configuration.
    
    how to use?

@endverbatim
  *
  * @{
  */


/**
  * @brief  lvd con register set
  * @param  p_lvd : pointer to the hardware LVD_TypeDef
  * @param  con_bit_map : lvd con register bit map
  * @retval None
  */
void ll_lvd_con_set(LVD_TypeDef *p_lvd, u32 con_bit_map);

/**
  * @brief  lvd con register get
  * @param  p_lvd : pointer to the hardware LVD_TypeDef
  * @retval lvd con register value
  */
u32 ll_lvd_con_get(LVD_TypeDef *p_lvd);

/**
  * @}
  */
  
/** @defgroup LVD_LL_Data_Transfers LVD LL Data transfers functions
  * @brief    LVD LL Data transfers functions 
  *
@verbatim   
  ===============================================================================
                            Data transfers functions
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the LVD data 
    transfers and receive.
  
@endverbatim
  *
  * @{
  */

/**
  * @brief  use for get vdd low voltage detector enable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vdd_enable(LVD_TypeDef *p_lvd);

/**
  * @brief  use for get vdd low voltage detector disable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vdd_disable(LVD_TypeDef *p_lvd);

/**
  * @brief  use for get vcc low voltage detector enable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vcc_enable(LVD_TypeDef *p_lvd);

/**
  * @brief  use for get vcc low voltage detector disable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vcc_disable(LVD_TypeDef *p_lvd);

/**
  * @brief  use for get vcc low voltage detector enable get
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval result
  */
#define LL_LVD_VCC_EN_GET(p_lvd)                            (p_lvd->LVD_CON & LL_LVD_CON_VCC_LVD_EN)

/**
  * @brief  use for get vdd low voltage detector debounce enable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vdd_debounce_enable(LVD_TypeDef *p_lvd);
/**
  * @brief  use for get vdd low voltage detector debounce disable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vdd_debounce_disable(LVD_TypeDef *p_lvd);
/**
  * @brief  use for get vdd low voltage detector debounce enable get
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval result
  */
#define LL_LVD_VDD_SHIELD_DEBOUNCE_EN_GET(p_lvd)            (p_lvd->LVD_CON & LL_LVD_CON_VDD_SHIELD_DEBOUNCE_EN)
/**
  * @brief  use for get vcc low voltage detector debounce enable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vcc_debounce_enable(LVD_TypeDef *p_lvd);
/**
  * @brief  use for get vcc low voltage detector debounce disable
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vcc_debounce_disable(LVD_TypeDef *p_lvd);
/**
  * @brief  use for get vcc low voltage detector debounce enable get
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval result
  */
#define LL_LVD_VCC_SHIELD_DEBOUNCE_EN_GET(p_lvd)            (p_lvd->LVD_CON & LL_LVD_CON_VCC_SHIELD_DEBOUNCE_EN) 

/**
  * @brief  enable VDD low voltage detector reset when threshold is triggered
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vdd_reset_enable(LVD_TypeDef *p_lvd);
/**
  * @brief  disable VDD low voltage detector reset when threshold is triggered
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vdd_reset_disable(LVD_TypeDef *p_lvd);
/**
  * @brief  VDD low voltage detector reset when threshold is triggered enable get
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval result
  */
#define LL_LVD_VDD_RESET_EN_GET(p_lvd)                      (p_lvd->LVD_CON & LL_LVD_CON_VDD_RST_EN)
/**
  * @brief  enable VCC low voltage detector reset when threshold is triggered
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vcc_reset_enable(LVD_TypeDef *p_lvd);
/**
  * @brief  disable VCC low voltage detector reset when threshold is triggered
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval none
  */
void ll_lvd_vcc_reset_disable(LVD_TypeDef *p_lvd);
/**
  * @brief   VCC low voltage detector reset when threshold is triggered enable get
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval result
  */
#define LL_LVD_VCC_RESET_EN_GET(p_lvd)                      (p_lvd->LVD_CON & LL_LVD_CON_VCC_RST_EN)

/**
  * @brief  use for get vdd interrupt low voltage detector pending 
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval value
  */
#define LL_LVD_VDD_PENDING_GET(p_lvd)                       ((p_lvd)->LVD_CON & LL_LVD_CON_VDD_PEND)
/**
  * @brief  use for clear vdd low voltage detector interrupt pending ( note: write 0 clean this bit )
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval None
  */
#define LL_LVD_VDD_PENDING_CLR(p_lvd)                       ((p_lvd)->LVD_CON = (p_lvd)->LVD_CON & (~LL_LVD_CON_VDD_PEND))

/**
  * @brief  use for get vcc low voltage detector interrupt pending 
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval None
  */
#define LL_LVD_VCC_PENDING_GET(p_lvd)                       ((p_lvd)->LVD_CON & LL_LVD_CON_VCC_PEND)
/**
* @brief  use for clear vcc low voltage detector interrupt pending ( note: write 0 clean this bit )
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval None
  */
#define LL_LVD_VCC_PENDING_CLR(p_lvd)                       ((p_lvd)->LVD_CON = (p_lvd)->LVD_CON & (~LL_LVD_CON_VCC_PEND))

/**
  * @brief  get vdd lvd set value
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval TYPE_ENUM_LL_LVD_VDD_LVD_SET
  */
TYPE_ENUM_LL_LVD_VDD_LVD_SET ll_lvd_vdd_lvd_get(LVD_TypeDef *p_lvd);

/**
  * @brief  get vcc lvd set value
  * @param  p_lvd: pointer to the hardware LVD_TypeDef *p_lvd
  * @retval TYPE_ENUM_LL_LVD_VCC_LVD_SET
  */
TYPE_ENUM_LL_LVD_VCC_LVD_SET ll_lvd_vcc_lvd_get(LVD_TypeDef *p_lvd);

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

/**
  * @}
  */

/**
  * @}
  */

#endif //__TS32F020X_LL_LVD_H

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
